<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/assets/plugins/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/assets/plugins/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-article-edit">
        <input id="id" name="id" th:value="${article.id}" type="hidden">
<!--        <div class="form-group">
            <label class="col-sm-3 control-label">栏目编号：</label>
            <div class="col-sm-8">
                <input id="categoryId" name="categoryId" th:value="${article.categoryId}" class="form-control"
                       type="text">
            </div>
        </div>-->
        <input id="categoryId" name="categoryId" th:value="${article.categoryId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" id="treeName" onclick="selectTree()" readonly="true"
                       th:value="${article.category ==null ?  '': article.category.name}"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input id="title" name="title" th:value="${article.title}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章链接：</label>
            <div class="col-sm-8">
                <input id="link" name="link" th:value="${article.link}" class="form-control" type="text">
            </div>
        </div>
<!--        <div class="form-group">
            <label class="col-sm-3 control-label">标题颜色：</label>
            <div class="col-sm-8">
                <input id="color" name="color" th:value="${article.color}" class="form-control" type="text">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">文章图片：</label>
            <div class="col-sm-8">
                <input id="image" name="image" th:value="${article.image}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">关键字：</label>
            <div class="col-sm-8">
                <input id="keywords" name="keywords" th:value="${article.keywords}" class="form-control" type="text"data-role="tagsinput">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述、摘要：</label>
            <div class="col-sm-8">
                <input id="description" name="description" th:value="${article.description}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章内容：</label>
            <div class="col-sm-8">
                <input id="content" name="content" th:value="${article.content}" class="form-control" type="hidden">
                <div id="editor" class="summernote"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文章来源：</label>
            <div class="col-sm-8">
                <input id="copyfrom" name="copyfrom" th:value="${article.copyfrom}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">禁止评论：</label>
            <div class="col-sm-8">
                <!--<input id="allowComment"  name="allowComment"th:value="${article.allowComment}" class="form-control time-input" type="text"> -->
                <div class="onoffswitch">
                    <input type="checkbox" th:checked="${article.allowComment? true : false}"
                           class="onoffswitch-checkbox" id="allowComment" name="allowComment">
                    <label class="onoffswitch-label" for="allowComment">
                        <span class="onoffswitch-switch"></span>
                        <span class="onoffswitch-inner"></span>
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权重，越大越靠前：</label>
            <div class="col-sm-8">
                <input id="weight" name="weight" th:value="${article.weight}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权重期限：</label>
            <div class="col-sm-8">
                <input id="weightDate" name="weightDate" th:value="${article.weightDate}"
                       class="form-control time-input" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">点击数：</label>
            <div class="col-sm-8">
                <input id="hits" name="hits" th:value="${article.hits}" class="form-control" type="text">
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">推荐位，多选：</label>
            <div class="col-sm-8">
                <input id="posid" name="posid" th:value="${article.posid}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">自定义内容视图：</label>
            <div class="col-sm-8">
                <input id="customContentView" name="customContentView" th:value="${article.customContentView}"
                       class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">视图配置：</label>
            <div class="col-sm-8">
                <input id="viewConfig" name="viewConfig" th:value="${article.viewConfig}" class="form-control"
                       type="text">
            </div>
        </div>-->
       <!-- <div class="form-group">
            <label class="col-sm-3 control-label">创建者：</label>
            <div class="col-sm-8">
                <input id="createBy" name="createBy" th:value="${article.createBy}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">创建时间：</label>
            <div class="col-sm-8">
                <input id="createTime" name="createTime" th:value="${article.createTime}"
                       class="form-control time-input" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">更新者：</label>
            <div class="col-sm-8">
                <input id="updateBy" name="updateBy" th:value="${article.updateBy}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">更新时间：</label>
            <div class="col-sm-8">
                <input id="updateTime" name="updateTime" th:value="${article.updateTime}"
                       class="form-control time-input" type="text">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">备注信息：</label>
            <div class="col-sm-8">
                <input id="remarks" name="remarks" th:value="${article.remarks}" class="form-control" type="text">
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">删除标记：</label>
            <div class="col-sm-8">
                &lt;!&ndash;<input id="delFlag"  name="delFlag"th:value="${article.delFlag}" class="form-control time-input" type="text"> &ndash;&gt;
                <div class="onoffswitch">
                    <input type="checkbox" th:checked="${article.delFlag? true : false}" class="onoffswitch-checkbox"
                           id="delFlag" name="delFlag">
                    <label class="onoffswitch-label" for="delFlag">
                        <span class="onoffswitch-switch"></span>
                        <span class="onoffswitch-inner"></span>
                    </label>
                </div>
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">相关文章：</label>
            <div class="col-sm-8">
                <input id="relation" name="relation" th:value="${article.relation}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/assets/plugins/summernote/summernote.min.js}"></script>
<script th:src="@{/assets/plugins/summernote/summernote-zh-CN.js}"></script>
<script type="text/javascript">
    var prefix = ctx + "cms/article";
    $(function() {
        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN'
        });
        var content = $("#content").val();
        $('#editor').summernote('code', content);
    });

    $("#form-article-edit").validate({
        onkeyup: false,
        rules: {
            xxxx: {
                required: true,
            },
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            var sHTML = $('.summernote').summernote('code');
            $("#content").val(sHTML);
            $.operate.save(prefix + "/editDo", $('#form-article-edit').serialize());
        }
    }
    function selectTree() {
        var id = $("#treeId").val();
        var options = {
            title: '选择上级',
            width: "380",
            url: ctx + "cms/category/selectTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {

        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        // 不允许最后层级节点选择
        // if ($.tree.notAllowLastLevel(tree)) {
        var body = layer.getChildFrame('body', index);
        // console.log(body.find('#treeId').val());
        $("#categoryId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
        // }
    }
</script>
</body>
</html>
